﻿@model NCP.Recruiting.WebApp.Models.CandidateListViewModel
@using NCP.Recruiting.WebApp.Models;
@using NCP.Recruiting.ApplicationServices.Shared;
@using NCP.Recruiting.WebApp.Extensions;
@{
    ViewBag.Title = "应聘管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
    var defaultValue = '@ViewBag.DefaultKeyword';

    $(document).ready(function () {
        //表格隔行变色，最后一行没有边框
        $('.wrapContents table tbody tr:last-child td').css({ 'border-bottom': 'none' });
        $('.wrapContents table tbody tr:even').css({ 'background': '#f0f0f0' });
        $('.wrapContents table tbody tr:even').css({ 'background': '#fbfbfb' });


        //导出
        $('.fbsx').click(function () {
            $(this).find('div').show();
            setTimeout(function () { $('.fbsx > div').hide(); }, 1000);
        });

        // 简历回复
        $('.receiptForm').dialog({
            autoOpen: false,
            height: 400,
            width: 450,
            modal: true,
            buttons: {
                "回复": function () {
                    var div = $("#receiptForm" + $('#hidSubmitId').val());
                    $.ajax({
                        url: '@Url.Action("ResumeReply")',
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify({
                            Id: $('#hidSubmitId').val(),
                            Jobseekers: div.find('#hidJobseekers').val(),
                            Subject: div.find('#hidSubject').val(),
                            Message: div.find('#hidMessage').val(),
                        }),
                        success: function (result) {
                            if (result) {
                                alert("简历回复成功！");

                                // 页面重置
                                $("#btnSearch").click();
                            }
                            else {
                                alert("简历回复失败，请重试！");
                            }
                        },
                        error: function (result) {
                            alert("简历回复失败，请重试！");
                        }

                    });

                    $(this).dialog("close");
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            },
            close: function () {
                $(this).dialog("close");
            }
        });

        // 邀请面试
        $('.interviewForm').dialog({
            autoOpen: false,
            height: 400,
            width: 450,
            modal: true,
            buttons: {
                "发送": function () {
                    var div = $("#interviewForm" + $('#hidSubmitId').val());
                    $.ajax({
                        url: '@Url.Action("InvitedToInterview")',
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify({
                            Id: $('#hidSubmitId').val(),
                            InterviewJobseekers: div.find('#hidInterviewJobseekers').val(),
                            InterviewDate: div.find('#hidInterviewDate').val(),
                            InterviewTime: div.find('#hidInterviewTime').val(),
                            InterviewLocation: div.find('#hidInterviewLocation').val(),
                            InterviewBody: div.find('#hidInterviewBody').val(),
                            InterviewSubject: div.find('#hidInterviewSubject').val(),
                        }),
                        success: function (result) {
                            if (result) {
                                alert("邀请面试成功！");

                                // 页面重置
                                $("#btnSearch").click();
                            }
                            else {
                                alert("邀请面试失败，请重试！");
                            }
                        },
                        error: function (result) {
                            alert("邀请面试失败，请重试！");
                        }

                    });

                    $(this).dialog("close");
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            },
            close: function () {
                $(this).dialog("close");
            }
        });

        //关键字输入框失去焦点
        $('#txtKeyword').bind('blur', function () {
            if (this.value == '') {
                this.value = defaultValue;
                this.className = "search_input";
            }
        });

        //关键字输入框获取焦点
        $('#txtKeyword').bind('focus', function () {
            if (this.value == defaultValue) {
                this.value = '';
            }
            this.className = "search_input_haveValue";
        });

        //过滤按钮点击事件
        $('#btnSearch').bind('click', function () {
            location.href = '@Url.Action("List")' + '?keyword=' + $('#txtKeyword').val() + '&queryStatus=' + $('#candidateQueryStatus').val();
            @*if ($('#txtKeyword').val() != defaultValue) {
                location.href = '@Url.Action("List")' + '?keyword=' + $('#txtKeyword').val() + '&queryStatus=' + $('#candidateQueryStatus').val();
            }
            else {
                alert('请输入关键字！');
            }*@
        });

        //初始化关键字输入框
        iniSearchTextBox(defaultValue);

        $('.chkAll').bind('click', function () {
            $('.itemChecked').attr('checked', $(this).attr('checked'));
        });

        // 简历回复
        $('#btnReceipt').bind('click', function () {
            $("#receiptForm" + $('#hidSubmitId').val()).dialog("open");
            return false;
        });

        // 邀请面试
        $('#btnInterview').bind('click', function () {
            $("#interviewForm" + $('#hidSubmitId').val()).dialog("open");
            return false;
        });

        //简历删除
        $('#btnDelete').bind('click', function () {
            var label = $(this).val();
            if (!confirm("确定要" + label + "简历吗？")) {
                return false;
            }
        });

        // 获取简历回复获取模版信息
        $('.ReplyTemplate').change(function () {
            var id = $(this).val();
            if (id == "00000000-0000-0000-0000-000000000000") {
                return false;
            }
            var hidMessage = $(this).parent().parent().find('#hidMessage');
            var text = hidMessage.val();
            if (text != null && text != "") {
                if (!confirm("已经有邮件内容，确定要替换吗？")) {
                    return false;
                }
            }

            $.ajax({
                url: '@Url.Action("GetTemplateContent")',
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({
                    Id: id
                }),
                success: function (result) {
                    if (result != null && result != "") {
                        hidMessage.val(result);
                    }
                    else {
                        alert("获取邮件内容失败！");
                    }
                },
                error: function (result) {
                    alert("获取邮件内容失败！");
                }
            });
            return false;
        });

        // 获取简历邀请模版信息
        $('.InterviewTemplate').change(function () {
            var id = $(this).val();
            if (id == "00000000-0000-0000-0000-000000000000") {
                return false;
            }
            var hidMessage = $(this).parent().parent().find('#hidInterviewBody');
            var text = hidMessage.val();
            if (text != null && text != "") {
                if (!confirm("已经有消息内容，确定要替换吗？")) {
                    return false;
                }
            }

            $.ajax({
                url: '@Url.Action("GetTemplateContent")',
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({
                    Id: id
                }),
                success: function (result) {
                    if (result != null && result != "") {
                        hidMessage.val(result);
                    }
                    else {
                        alert("获取消息内容失败！");
                    }
                },
                error: function (result) {
                    alert("获取消息内容失败！");
                }
            });
            return false;

        });

        //批处理操作按钮点击事件
        $('.batchAction').bind('click', function () {
            var label = $(this).val();
            if ($('.itemChecked:checked').length == 0) {
                alert("请选择要" + label + "的简历！");
                return false;
            }
            else {
                if (!confirm("确定要" + label + "所选简历吗？")) {
                    return false;
                }
            }
        });

        $('.restore').bind('click', function () {
            $('#hidSubmitId').val($(this).parent().find('#hidId').val());
            $('#btnRestore').click();
        });

        //设置弹出菜单
        $('.select').button({
            text: false,
            //text: "管理",
            icons: {
                primary: "ui-icon-triangle-1-s"
            }
        }).click(function () {
            //设置菜单状态
            var status = $(this).parent().find('#hidStatus').val();
            var lbtnreceipt = $('#lbtnreceipt');
            var lbtnInterview = $('#lbtnInterview');
            lbtnreceipt.show();
            lbtnInterview.show();

            $('#hidSubmitId').val($(this).parent().find('#hidId').val());

            var menu = $('#menuItem').show().position({
                my: "right top",
                at: "right bottom",
                of: this
            });

            $(document).one("click", function () {
                menu.hide();
            });

            return false;
        });

        $('#menuItem').hide().menu();

    });

    function iniSearchTextBox(defaultValue) {
        if ($('#txtKeyword').val() == "") {
            $('#txtKeyword').val(defaultValue);
        }
        $('#txtKeyword').toggleClass("search_input", $('#txtKeyword').val() == defaultValue);
        $('#txtKeyword').toggleClass("search_input_haveValue", $('#txtKeyword').val() != defaultValue);
    };

    function unreadClick(id) {
        $.ajax({
            url: '@Url.Action("SetIsReadLetter", "Candidate")',
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify({
                Id: id
            }),
            success: function (result) {
                if (result) {
                    alert("设定成功！");

                    // 页面重置
                    $("#btnSearch").click();
                }
                else {
                    alert("设定失败，请重试！");
                }
            },
            error: function (result) {
                alert("设定失败，请重试！");
            }
        });
        return false;
    }
</script>

<div id="wrap">
    <div class="wrapContents">
        @using (Html.BeginForm())
        {
            <input class="batchAction" type="submit" value="查看所选" id="btnPostSelected" name="PriviewSelected"
                   style="display: none" />
            <input class="batchAction" type="submit" value="下载所选简历" id="btnPauseSelected" name="PauseSelected"
                   style="display: none" />
            <input class="batchAction" type="submit" value="删除" id="btnDeleteSelect" name="DeleteSelected"
                   style="display: none" />
            <h1>
                应聘管理
            </h1>
            <div class="positions">
                @Html.ActionLink("最新简历", "List", new { queryStatus = CandidateQueryStatus.All }, new { @class = Model.CandidateQueryStatus == CandidateQueryStatus.All ? "cur" : "none" })
                @Html.ActionLink("自选简历", "List", new { queryStatus = CandidateQueryStatus.Optional }, new { @class = Model.CandidateQueryStatus == CandidateQueryStatus.Optional ? "cur" : "none" })
                @Html.ActionLink("已发信息", "List", new { queryStatus = CandidateQueryStatus.Replied }, new { @class = Model.CandidateQueryStatus == CandidateQueryStatus.Replied ? "cur" : "none" })
                @Html.ActionLink("已置标签", "List", new { queryStatus = CandidateQueryStatus.Taged }, new { @class = Model.CandidateQueryStatus == CandidateQueryStatus.Taged ? "cur" : "none" })
                @Html.ActionLink("已置状态", "List", new { queryStatus = CandidateQueryStatus.Status }, new { @class = Model.CandidateQueryStatus == CandidateQueryStatus.Status ? "cur" : "none" })
                @Html.ActionLink("星标简历", "List", new { queryStatus = CandidateQueryStatus.Marked }, new { @class = Model.CandidateQueryStatus == CandidateQueryStatus.Marked ? "cur" : "none" })
                @*@Html.ActionLink("已删除简历", "List", new { queryStatus = CandidateQueryStatus.Deleted }, new { @class = Model.CandidateQueryStatus == CandidateQueryStatus.Deleted ? "cur" : "none" })*@
            </div>
            <div class="search">
                <div class="search_left">
                    <div class="caozuo">
                        <a href="#" onclick="$('#btnDeleteSelect').click()">删除所选</a>
                    </div>
                    <div class="seachBox">
                        @Html.HiddenFor(x => x.CandidateQueryStatus, new { id = "candidateQueryStatus" })
                        @Html.TextBoxFor(x => x.Keyword, new { @class = "search_input", id = "txtKeyword" })
                        <input id="btnSearch" class="searchBtns" value="过滤" style="text-align: center" />
                    </div>
                    <div class="gjss">
                        <a href="#">高级搜索</a>
                    </div>
                    <div class="cl">
                    </div>
                </div>
                <div class="search_right">
                    @Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber")
                </div>
                <div class="cr">
                </div>
            </div>
            <table cellpadding="0" cellspacing="0" id="gd_tab">
                <thead>
                    <tr>
                        <th style="width:27px;">
                            <input class="chkAll" type="checkbox" />
                        </th>
                        <th style="width:33px;">&nbsp;</th>
                        <th style="width:40px;">来源</th>
                        <th style="width:141px;">应聘职位/求职信</th>
                        <th style="width:70px;">简历ID</th>
                        <th style="width:53px;">姓名</th>
                        <th style="width:59px;">年龄</th>
                        <th style="width:78px;">工作经验</th>
                        <th style="width:52px;">学历</th>
                        <th style="width:84px;">联系电话</th>
                        <th style="width:68px;">接收日期</th>
                        <th style="width:65px;">处理日期</th>
                        <th style="width:42px;">状态</th>
                        <th style="width:139px;">&nbsp;</th>
                        <th style="width:28px;">星标</th>
                        <th style="width:32px;">操作</th>
                    </tr>
                </thead>
                <tbody id="tbodyJobList">
                    @Html.EditorFor(x => x.CandidateList)
                </tbody>
            </table>
            <div class="pagelists">
                <div class="pagelists_btns">
                    <div class="allCheck">
                        <input class="chkAll" type="checkbox" /><span>全选</span>
                    </div>
                    <a href="#" onclick="$('#btnPostSelected').click()" class="sxzw">查看所选</a> <a href="#"
                                                                                                 onclick="$('#btnPauseSelected').click()" class="sxpx">发消息</a><a href="#" class="fbsx">导出<div><ul><li>Excel (当前字段)</li><li>Excel (所有字段)</li></ul></div></a>
                </div>
                <div class="search_right">
                    @Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber")
                </div>
                <div class="cr">
                </div>
            </div>
        }
        <ul id="menuItem" style="width: 70px; position: absolute; z-index: 100">
            <li><a href="#" onclick="$('#btnReceipt').click()" id="lbtnreceipt">标注简历</a></li>
            <li><a href="#" onclick="$('#btnInterview').click()" id="lbtnInterview">发消息</a></li>
            <li><a href="#" onclick="$('#btnDelete').click()" id="lbtnDelete">删除</a></li>
        </ul>
        @using (Html.BeginForm(new { queryStatus = Model.CandidateQueryStatus, keyword = Model.Keyword }))
        {
            <input type="hidden" name="id" id="hidSubmitId" />
            <input type="hidden" name="jobseekers" id="hidSubmithJobseekers">
            <input type="hidden" name="keyword" id="hidSubmitKeyword" />
            <input class="action" type="submit" value="标注简历" id="btnReceipt" name="receipt" style="display: none" />
            <input class="action" type="submit" value="发消息" id="btnInterview" name="interview"
                   style="display: none" />
            <input class="action" type="submit" value="删除" id="btnDelete" name="Delete" style="display: none" />
        }
    </div>
</div>
